URL = r"http://download.savannah.nongnu.org/releases/openexr/ilmbase-%(VERSION)s.tar.gz"
DEFAULT_VERSION = "2.1.0"
VERSIONS = ["2.1.0"]

from source.builders import CMakeBuilder, ConfigureMakeBuilder
import os, sys

class ILMBaseConfigureMakeBuilder( ConfigureMakeBuilder ):
  """ subclass of ConfigureMakeBuilder with custom configure step """
  def configureparameters(self):
    params = []
    return params


class IlmBaseBuilder( CMakeBuilder ):
  """ subclass of CMakeBuilder with custom configure step """

  def configure(self):
    """upgrade the files and build the solution """
    os.chdir( self.extractedpath )    
    if self.machine.platform == 'Windows':
      self.copyfile(sys.path[0]+"/library/additions/stdint.h", self.extractedpath+os.sep+"config")
      if not '#define PLATFORM_WINDOWS' in open("config.windows\\IlmBaseConfig.h").read():
        with open("config.windows\\IlmBaseConfig.h", "a") as configfile:
          configfile.write("#define PLATFORM_WINDOWS\n")
    params = ' -DCMAKE_DEBUG_POSTFIX="d" -DHALF_EXPORTS:BOOL=ON '
    CMakeBuilder.configure(self, additional_args=params)

def decider( machine, dirs ):
  return { "Linux" : ILMBaseConfigureMakeBuilder,
           "Windows" : IlmBaseBuilder }[machine.platform]

BUILDER = decider

